﻿using System;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RuanRang.Core;
using RuanRang.Core.Common;
using RuanRang.Core.Render;

namespace PDFTest
{
    [TestClass]
    public class TestPdfRender
    {
        /// <summary>
        /// Tests the load assembly.
        /// </summary>
        [TestMethod]
        public RenderPluginContainer TestLoadAssembly()
        {
            const string file = @"D:\Microsoft SkyDrive\SkyDrive\组件\word_pdf_Plugins\Plugins\PDFRender.dll";
            var assemblyContainer = new RenderPluginContainer();
            assemblyContainer.Register(RenderPluginType.PDF, file);
            Assert.IsNotNull(assemblyContainer);
            return assemblyContainer;
        }

        /// <summary>
        /// Tests the load PDF.
        /// </summary>
        [TestMethod]
        public PDFRender TestLoadPDF()
        {
            var render = TestLoadAssembly();
            var pdf = new PDFRender(render);
            Assert.IsNotNull(pdf);
            const string pdfFile = @"H:\TFS_My Work\My Work\CourseToolSuite\Tools\LibTest\bin\Debug\1.pdf";
            pdf.Open(pdfFile);
            pdf.OpenCompleted += (sender, args) => Trace.WriteLine("Open Async Completed");
            pdf.OpenAsync(pdfFile);
            Assert.IsNotNull(pdf.TargetFile);
            Trace.WriteLine("Page Count: " + pdf.PageCount);
            return pdf;
        }

        /// <summary>
        /// Tests the save image.
        /// </summary>
        [TestMethod]
        public void TestSaveImage()
        {
            var pdf = TestLoadPDF();
            pdf.Save(@"H:\TFS_My Work\My Work\CourseToolSuite\Tools\LibTest\bin\Debug\Test", "PDF");
        }

        /// <summary>
        /// Tests the get image.
        /// </summary>
        [TestMethod]
        public void TestGetImage()
        {
            var pdf = TestLoadPDF();
            //pdf.GetImageCompleted += (sender, args) =>
            //{
            //    var imgeArg = args as ImageEventArgs;
            //    Assert.IsNotNull(imgeArg);
            //    Assert.IsFalse(imgeArg.ImageDictionary.Count > 0);
            //    Trace.WriteLine("Get Image Async Completed");
            //}; 
            var img = pdf.GetImage(0);
            //pdf.GetImageAsync(0);
            //Assert.IsNotNull(imgeArg);
            Assert.IsNotNull(img);
            img.Dispose();
            img = null;
            Assert.IsNull(img);
        }
    }
}
